package kuaidi;

import javax.swing.*;
import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

public class AdminActionsPanel extends JPanel {

    public AdminActionsPanel(CardLayout cardLayout, JPanel mainPanel) {
        setLayout(new GridBagLayout());
        setBackground(Color.WHITE);

        // 创建按钮
        JButton importBtn = new JButton("导入包裹");
        JButton retrieveBtn = new JButton("取走包裹");

        // 设置按钮样式
        setupStyledButton(importBtn, new Color(0, 255, 255), new Color(0, 206, 209));   // 青色
        setupStyledButton(retrieveBtn, new Color(255, 215, 0), new Color(255, 165, 0)); // 橙色

        // 添加按钮事件
        importBtn.addActionListener(e -> cardLayout.show(mainPanel, "import"));
        retrieveBtn.addActionListener(e -> cardLayout.show(mainPanel, "retrieve"));

        // 使用 GridBagLayout 布局添加按钮
        GridBagConstraints gbc = new GridBagConstraints();
        gbc.insets = new Insets(15, 15, 15, 15);
        gbc.gridx = 0;
        gbc.fill = GridBagConstraints.HORIZONTAL;

        gbc.gridy = 0;
        add(importBtn, gbc);

        gbc.gridy = 1;
        add(retrieveBtn, gbc);
    }

    /**
     * 美化按钮样式：字体、颜色、圆角、悬停颜色等
     */
    private void setupStyledButton(JButton button, Color normalColor, Color hoverColor) {
        button.setFont(new Font("微软雅黑", Font.BOLD, 16));
        button.setForeground(Color.BLACK);
        button.setBackground(normalColor);
        button.setFocusPainted(false);
        button.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
        button.setPreferredSize(new Dimension(140, 45));
        button.setBorder(BorderFactory.createLineBorder(Color.DARK_GRAY, 1));

        // 悬停效果
        button.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseEntered(MouseEvent e) {
                button.setBackground(hoverColor);
            }

            @Override
            public void mouseExited(MouseEvent e) {
                button.setBackground(normalColor);
            }
        });
    }
}
